import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'text_controller.dart';
import 'package:test_app/weigets/clipboard/index.dart';
import 'package:test_app/core/base/base/base_view.dart';
import 'package:test_app/core/design_system/theme/color.dart';
import 'package:test_app/core/design_system/extensions/extensions.dart';

typedef OnTapWithCtx = VoidCallback? Function(BuildContext context);

class TextView extends BaseView<TextController> {
  const TextView({super.key});

  @override
  String? get navTitle => "详情";

  @override
  Widget body() {
    return Builder(builder: (context) {
      return [
        box(
          Text(controller.textState.text).copyWith(maxLines: 1).width(100),
          title: '自定义长度的文字且展示一行',
            code: 'Text(controller.textState.text).copyWith(maxLines: 1).width(100)'
        ),
        box(
          Text(controller.textState.text,).copyWith(maxLines: 1, overflow: TextOverflow.ellipsis),
          title: '自定义长度的文字且展示一行 溢出...',
            code: 'Text(controller.textState.text,).copyWith(maxLines: 1, overflow: TextOverflow.ellipsis)'
        ),
        box(
          Text(controller.textState.text).copyWith(maxLines: 2, overflow: TextOverflow.ellipsis),
          onTap: (BuildContext context) {
            return () {
              TDPopover.showPopover(
                context: context,
                contentWidget: Text(
                  controller.textState.text,
                ).textColor(Colors.amberAccent),
                showArrow: true,
                width: 200,
                height: 120,
              );
            };
          },
          title: '多行文本 溢出...',
            code: 'Text(controller.textState.text).copyWith(maxLines: 2, overflow: TextOverflow.ellipsis)'
        ),
      ].toColumnStart(spacing: 20.0).padAll(10).bouncingScroll();
    });
  }

  Widget box(Widget child, {required String title, OnTapWithCtx? onTap, required String code}) {
    return [
      Text(title),
      Builder(builder: (BuildContext context) {
        return child.padAll(10)
            .animatedTapScale(onTap?.call(context), color: primaryLight)
            .backgroundColor(primaryLight)
            .border(all: 1, radius: 6, color: primaryDark);
      }),
      Clipboard(code: code)
    ].toColumnStart(spacing: 15);
  }
}
